﻿using System;
using System.Collections.Generic;
using System.Windows.Input;

namespace Foundation
{
    public class SharedCommands : PropertyNameProvider
    {
        private static readonly Dictionary<string, ICommand> Commands = new Dictionary<string, ICommand>();

        public static ICommand New { get { return Get("New"); } }
        public static ICommand Open { get { return Get("Open"); } }
        public static ICommand Save { get { return Get("Save"); } }
        public static ICommand Dry { get { return Get("Dry"); } }
        public static ICommand Back { get { return Get("Back"); } }
        public static ICommand Next { get { return Get("Next"); } }
        public static ICommand Cut { get { return Get("Cut"); } }
        public static ICommand Copy { get { return Get("Copy"); } }
        public static ICommand Paste { get { return Get("Paste"); } }
        public static ICommand Delete { get { return Get("Delete"); } }

        public static ICommand Get(string commandName)
        {
            if (!Commands.ContainsKey(commandName))
                Commands.Add(commandName, new SharedCommand(commandName));
            return Commands[commandName];
        }

        public static void UpdateCanExecuteState()
        {
            foreach (SharedCommand command in Commands.Values)
            {
                command.RaiseCanExecuteChanged();
            }
        }
    }

    public class SharedCommand : ICommand
    {
        public string Name { get; private set; }

        public SharedCommand(string name)
        {
            Name = name;
            //Touch.FrameReported += (sender, args) => CanExecuteChanged(sender, args);
        }

        public void RaiseCanExecuteChanged()
        {
            CanExecuteChanged(this, EventArgs.Empty);
        }

        public bool CanExecute(object parameter)
        {
            throw new NotImplementedException();
        }

        public void Execute(object parameter)
        {
            //SharedCommands.UpdateCanExecuteState();
            throw new NotImplementedException();
        }

        public event EventHandler CanExecuteChanged = (sender, args) => { };
    }
}
